package com.sunny.l22;


public class Solution {
    private int res = 0;
    public int sumNumbers(TreeNode root) {
        if(null == root)
            return 0;
        dfs(root, 0);
        return res;
    }

    public void dfs(TreeNode node, int num){
        int value = num*10 + node.val;
        if(null != node.left){
            dfs(node.left, value);
        }
        if(null != node.right){
            dfs(node.right, value);
        }
        if(null == node.left && null == node.right){
            res += value;
        }
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}
